#ifndef _ASYNCUDPSOCKIMPL_H_
#define _ASYNCUDPSOCKIMPL_H_

#include "stdafx.h"

class CUdpSocketImpl : public IUdpSocket, public CUnknownImp
{
public:
    CUdpSocketImpl(void);
    virtual ~CUdpSocketImpl(void);

    BEGIN_STDCOM_MAP
    STDCOM_INTERFACE_ENTRY(IUdpSocket)
    STDCOM_INTERFACE_ENTRY_UNKNOWN_(IUdpSocket)
    END_STDCOM_MAP

public:
    HRESULT CreateIoOperation(IAsynFrame* pIAsynFrame);
    HRESULT BindEvloop(ioevloop_t* loop);

public:
    // IIoDevice
    std_method(CloseIo)(UINT rw);
    std_method(BindIo)();
    std_method(OpenIo)();

    // ISocket
    std_method(BindEvent)(IBase* pSocketEvent);
    std_method(UnBindEvent)();
    std_method(CreateSock)();
    std_method(CloseSock)();
    std_method(IsOpen)();
    std_method(AttachSock)(_sock_t sock);
    std_method_(_sock_t, DetachSock)();
    std_method_(_sock_t, GetSock)();
    std_method(GetReadOperation)(IID id, IBase** pBase);
    std_method(GetWriteOperation)(IID id, IBase** pBase);

    // IUdpSocket
    std_method(ReadIo)(NET_ADDR addr, NET_PORT port, IBase* pBase, crtid event);
    std_method(WriteIo)(NET_ADDR addr, NET_PORT port, IBase* pBase, crtid event);

private:
    _sock_t m_sock;
    CharArrayPtr m_pAddr;
    NET_PORT m_uPort;
    _lComPtr<IOperation> m_pReadOperation;
    _lComPtr<IOperation> m_pWriteOperation;
};

#endif
